<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = path + "/resource/extjs/skins/default";
%>
<html>
	<head>
		<jsp:include page="/common.jsp" />
		<!-- include common.jsp -->
		<base />
		<script type="text/javascript">
			var companyId='<%=request.getParameter("companyId")%>' ;
		</script>
		<script type="text/javascript">
		var basePath='<%=basePath%>';
		var path='<%=path%>';
		var form_create_company;
		var tree=window.parent.Ext.getCmp("classTree");
		function updateCompany(){
			form_create_company.getForm().submit({
				url:path+'/classify/createCompany.do',
				waitMsg:'load...',
				success:function(){
					tree.root.reload();
				}	
			})
		};
		var combo_secondClass=new Ext.form.ComboBox({
	        id:'combo_secondClass',
	     	name:'combo_secondClass',
	     	fieldLabel :'所属类别',
	     	hiddenName:'classId',
		  	store : new Ext.data.ArrayStore({
			  	fields : ['classId', 'className']
			}),	
		  	valueField :'classId',
		  	displayField :'className',
		  	mode : 'local',
		  	triggerAction :'all',
		  	emptyText:'请选择',
		  	editable:false
		});
		var win_upload=new Ext.Window({
			title:'上传图片',
			frame:true,
			plain:true,
			width:300,
			height:200,
			modal:true,
			closeAction:'hide',
			buttons:[{
	    		text:'关闭',
	    		handler:function(){
	    			win_upload.hide();
	    		}
	    	}]
		})
		
		var store_company_pic;
		function deletePic(id){
			var r=confirm("确定要删除吗");
			if(r==true){
				Ext.Ajax.request({
					url:path+'/picture/deletePic.do',
					params:{"picId":id,"type":"company"},
					success:reload
				});
			}
		};
		function reload(){
			store_company_pic.load({
				callback:function(rec,opt){
					
				}
			});
		};
	    Ext.onReady(function(){
		    form_create_company = new Ext.form.FormPanel({
	    		frame:true,
				border : false,
				renderTo:'form_create_company',
				id:'from_add_company',
				//fileUpload:true,
				border:false,
				width:450,
				defaultType: 'textfield',
				bodyStyle:'padding:10px 5px 0 20px',
				defaults: {width: 230},
				reader:new Ext.data.JsonReader({
					root:'data',
					successProperty:'success'
				},[
						{name: 'companyId',mapping:'companyId'},
				        {name: 'companyName',mapping:'companyName'},
				        {name: 'companyDesc',mapping:'companyDesc'},
				        {name: 'linkMan',mapping:'linkMan'},
				        {name: 'phone',mapping:'phone'},
				        {name: 'address',mapping:'address'},
				        {name: 'busLine',mapping:'busLine'},
				        {name: 'siteUrl',mapping:'siteUrl'},
				        {name: 'briefInfo',mapping:'briefInfo'},
				        {name: 'displayOrder',mapping:'displayOrder'},
				        {name: 'state',mapping:'state'}
				]),
				items: [{
					name:'companyId',
					hidden:true
				},{
	                fieldLabel: '公司名称',
	                name: 'companyName',
	                allowBlank:false
	            },{
	                fieldLabel: '描述',
	                name: 'companyDesc'
	            },{
	                fieldLabel: '联系人',
	                name: 'linkMan'
	            },{
	                fieldLabel: '电话',
	                name: 'phone'
	            },{
	                fieldLabel: '公司地址',
	                name: 'address'
	            },{
	                fieldLabel: '乘车路线',
	                name: 'busLine'
	            },{
	                fieldLabel: '网址',
	                name: 'siteUrl'
	            },{
	            	xtype:'textarea',
	            	height:140,
	                fieldLabel: '公司简介',
	                name: 'briefInfo'
	            },{
	                fieldLabel: '顺序',
	                name: 'displayOrder'
	            },combo_secondClass,{
		            	xtype: 'radiogroup',
			            fieldLabel: '激活',
			            name:'state',
			            items: [
			                {boxLabel: '是', name: 'state', inputValue: 1},
			                {boxLabel: '否', name: 'state', inputValue: 0}
			            ]
		        },{
           			xtype:'button',
           			text:'缩略图上传',
           			width:'100',
           			style: 'margin-left:84px;',
           			handler:function(){
           				window.open(path+'/manage/common/upload.jsp?companyId='+companyId,'','height=200,width=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');
           			}
           		}],
		            buttons:[{
		            	text:'修改',
		            	handler:updateCompany
					}]
			});
			form_create_company.getForm().load({
				url:path+"/classify/loadCompany.do",
				params:{"companyId":companyId}
			});
			Ext.Ajax.request({
				url:path+'/classify/loadAllSecondClassify.do',
				params:{"companyId":companyId},
				success:function(str){
					var str=Ext.util.JSON.decode(str.responseText);
					var value=str.value;
					var data=str.data;
					combo_secondClass.store.loadData(data);
					combo_secondClass.setValue(value);
				}
			});
			
			store_company_pic=new Ext.data.Store({
	    		baseParams:{"companyId":companyId},
				proxy: new Ext.data.HttpProxy({
					url:path+'/classify/loadCompanyPicList.do'
				}),
				reader: new Ext.data.JsonReader({
					root:'root',
					fields:[
						{name:'picName'},
						{name:'picUrl'},
						{name:'displayOrder'},
						{name:'picId'},
						{name:'opt'}
					]
				})
			});
			var grid_company_pic=new Ext.grid.GridPanel({
				//autoHeight:true,
				frame:true,
				store:store_company_pic,
				renderTo:'grid_company_pic',
				//border:false,
				autoScroll:true,
				height:220,
				width:450,
				viewConfig: { forceFit:true},
				columns:[
					{header:'名称',align:'center',dataindex:'picName'},
					{header:'位置',align:'center',dataindex:'picUrl'},
					{header:'顺序',align:'center',dataindex:'displayOrder'},
					{header:'操作',align:'center',dataindex:'opt',renderer:function(v1,v2,rec){
						return '<a href="javascript:void(0);" onclick="deletePic(\''+rec.data.picId+'\')">删除</a>'
					}}
				],
				buttons:[{
	            	text:'广告图片上传',
	            	id:'upload',
	            	handler:function(){
	            		var value=window.showModalDialog(path+'/manage/classify/uploadCompanyPic.jsp?companyId='+companyId,'','dialogHeight=200px;dialogWidth=400px;toolbar=no;menubar=no;scrollbars=yes;resizable=no;location=no;status=no;');
	            		if(value=='true'){
	            			reload();
	            		}
	            	}
				}]
			});
			reload();
		});
		</script>
	</head>
	<body>
		<style>
			body {
			margin: 0;
			padding: 0 0 12px 0;
			font-size: 12px;
			line-height: 22px;
			font-family: "宋体", "Arial Narrow";
			background: #fff;
		}
		</style>
		<div id="form_create_company">
		</div>
		<div id="grid_company_pic">
		</div>
	</body>
</html>
